{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* By: Illya Barziy\n",
    "* Email: illyabarziy@gmail.com\n",
    "* Reference: __Estimation of Theory-Implied Correlation__ _by_ Marcos Lopez de Prado"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## The Theory-Implied Correlation algorithm (TIC)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This description of the algorithm and the realizations in the mlfinlab package are based on the paper by _Marcos Lopez de Prado_ __Estimation of Theory-Implied Correlation Matrices__  [available here](https://papers.ssrn.com/sol3/abstract_id=3484152). Quotation marks are used in the descriptions below to indicate direct quotes from the paper.\n",
    "\n",
    "The Correlation Matrix Distance metric is described in a paper by _Markus Herdin_ and _Ernst Bonek_ __AMIMO Correlation Matrix based Metric for Characterizing Non-Stationarity__ [available here](https://publik.tuwien.ac.at/files/pub-et_8791.pdf).\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Introduction"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In finance, the correlation matrices are widely used in portfolio management and a variety of other tasks. As they are calculated based on the series of historical observations, they pose the following caveats:\n",
    "- \"Empirical correlation matrices have poor numerical properties and as a result, unreliable estimators\". Some of the examples of these problems are described in the NCO notebook [available here](https://github.com/hudson-and-thames/research/blob/master/NCO/NCO.ipynb)\n",
    "- \"Empirical correlation matrices have poor predictive power\".\n",
    "\n",
    "There are also factor-based correlation matrices, that have the following caveats:\n",
    "- \"Factor-based correlation matrices are typically non-hierarchical. And instruments are usually exhibiting a nested cluster structure\".\n",
    "\n",
    "The TIC algorithm estimates the forward-looking correlation matrix implied by a proposed hierarchical structure of the assets. This hierarchical structure can be implied from economic theory or alternative classification methods. "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Motivation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\"The numerical problems [of the empirical correlation matrices] have traditionally  been  addressed  by  shrinking  the  correlation matrix  (in a work by _Ledoit_  and _Wolf_ [available here](http://perso.ens-lyon.fr/patrick.flandrin/LedoitWolf_JMA2004.pdf))\". \n",
    "\n",
    "\"Shrinkage eliminates some of the noise in the correlation matrix, at the cost of diluting much of the signal. A better approach is to shrink only the eigenvalues associated with noise (in the works by _Potter et al._ [available here](https://arxiv.org/abs/physics/0507111), and by _Lopez de Prado_ [available here](https://www.cambridge.org/core/books/machine-learning-for-asset-managers/6D9211305EA2E425D33A9F38D0AE3545))\".\n",
    "\n",
    "Another problem that requires a solution is the lack of the user-defined structure of the correlation matrices. This would add \"forward-looking views of the world (in contrast to the backward-looking views of empirical correlations)\".\n",
    "\n",
    "\"Academics  and  practitioners  often  work  with  factor-based  correlation matrices,  where  the economic factors impose a theoretical structure. Factor-based correlation matrices pose problems of their own: \n",
    " - (a) the factors are not robustly estimated, because they are derived from empirical correlation  matrices,  subject  to  the  same  numerical  ill-conditioning;  \n",
    " - (b)  the  factors  do  not represent  forward-looking  views,  because  they  are  estimated  from  historical  series;\n",
    " - (c) factor-based  correlation matrices  are  derived  from  structural  regression  models  that fail  to recognize  the  complex  hierarchical  interactions  among  securities.\"\n",
    "\n",
    "An example of a hierarchical structure for the financial instruments is the __MSCI’s Global Industry  Classification  Standard  (GICS)__ [(link)](https://www.msci.com/gics) that classifies investment  universes  in  terms  of four nested levels."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Input data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The algorithm combines empirical data - the correlation matrix of the assets with the fundamental structure provided by the economic theory - the hierarchical structure of the assets.\n",
    "\n",
    "\"This  departure [of the theory-implied  correlation  matrix from the empirical correlation matrix]  can  be  justified  in  terms  of:  \n",
    "- (a)  the  need  to  correct  for  spurious correlations,  driven  by  noise  rather  than  signal; \n",
    "- (b)  the  desire  to  make  a  forward-looking statement, rather than the backward-looking views expressed by historical correlations.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Tree graph"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The tree graph, representing the economic theory and the hierarchical structure of the assets \"can have as many  levels  as  needed,  with  one  or  more leaves  per  branch,  and  some  branches  may  include more  levels  than  other  branches\".\n",
    "\n",
    "The assets may be also grouped according to structures of other nature than those of economic theory, such as knowledge graphs (from the work of _Liu et al._ [available here](https://link.springer.com/chapter/10.1007/978-3-319-97289-3_8)), that are build based on the position of the companies to others in terms of business ties, competitors etc. based on the data extracted from the news articles.\n",
    "\n",
    "\"The columns [in a tree graph] are ordered bottom-up, with the leftmost column corresponding to the terminal leaves, and the rightmost column corresponding to the tree's root\".\n",
    "\n",
    "A tree graph based on the GICS to use in the algorithm may look as follows:\n",
    "\n",
    "\n",
    "| Ticker        | Sub-Industry   | Industry  | Industry Group  | Sector  |\n",
    "|---------------|----------------|-----------|-----------------|---------|\n",
    "| A UN Equity   | 35203010       | 352030    | 3520            | 35      |\n",
    "| AAL UW Equity | 20302010       | 203020    | 2030            | 20      |\n",
    "| AAP UN Equity | 25504050       | 255040    | 2550            | 25      |\n",
    "| AAPL UW Equity| 45202030       | 452020    | 4520            | 45      |"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Empirical correlation matrix"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The correlation matrix, representing the empirical data is estimated based on historical observations.\n",
    "\n",
    "\"This empirical correlation matrix must be symmetric, and include a main diagonal of 1s. However, the empirical correlation matrix does not need to be invertible, positive definite  or  non-singular.\"\n",
    "\n",
    "A correlation matrix based on historical data to use in the algorithm may look as follows:\n",
    "\n",
    "\n",
    "| Ticker            | A UN Equity | AAL UW Equity | AAP UN Equity | AAPL UW Equity |\n",
    "|-------------------|-------------|---------------|---------------|----------------|\n",
    "| **A UN Equity**   | 1           | 0.73          | 0.65          | 0.77           |\n",
    "| **AAL UW Equity** | 0.73        | 1             | 0.82          | 0.75           |\n",
    "| **AAP UN Equity** | 0.65        | 0.82          | 1             | 0.59           |\n",
    "| **AAPL UW Equity**| 0.77        | 0.75          | 0.59          | 1              |"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### The TIC algorithm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The TIC algorithm consists of three steps:\n",
    "\n",
    "1. __In the first step, the theoretical tree graph structure of the assets is fit on the evidence presented by the empirical correlation matrix.__\n",
    "\n",
    " - If there is no top level of the tree (tree root), this level is added so that all variables are included in one general cluster.\n",
    "\n",
    " - The empirical correlation matrix is transformed into a matrix of distances using the above formula:\n",
    "\n",
    "    $$d_{i,j} = \\sqrt{\\frac{1}{2}(1 - \\rho{i,j})}$$\n",
    "\n",
    " - For each level of the tree, the elements are grouped by elements from the higher level. The algorithm iterates from the lowest to the highest level of the tree.\n",
    "\n",
    " - A linkage object is created for these grouped elements based on their distance matrix using the [SciPy linkage function](https://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy.linkage.html). Each link in the linkage object is an array representing a cluster of two elements and has the following data as elements:\n",
    "    - ID of the first element in a cluster\n",
    "\n",
    "    - ID of the second element in a cluster\n",
    "\n",
    "    - Distance between the elements\n",
    "\n",
    "    - Number of atoms (simple elements from the portfolio and not clusters) inside\n",
    "\n",
    " - A linkage object is transformed to reflect the previously created clusters.\n",
    "\n",
    " - A transformed local linkage object is added to the global linkage object\n",
    "\n",
    " - Distance matrix is adjusted to the newly created clusters - elements that are now in the new clusters are replaced by the clusters in the distance matrix. The distance from the new clusters to the rest of the elements in the distance matrix is calculated as a weighted average of distances of two elements in a cluster to the other elements. The weight is the number of atoms in an element. So, the formula is:\n",
    "\n",
    "$$DistanceCluster = \\frac{Distance_1 * NumAtoms_1 + Distance_2 * NumAtoms_2}{NumAtoms_1 + NumAtoms_2}$$\n",
    "\n",
    " - The linkage object, representing a dendrogram of all elements in a portfolio is the result of the first step of the algorithm. It sequentially clusters two elements together, while measuring how closely together the two elements are, until all elements are subsumed within the same cluster.\n",
    "\n",
    "\"Note that the dendrogram  is  not the  tree  graph.  The  tree  graph  could  have  one  or  more  leaves  per  branch, whereas  the  dendrogram  always  has  two  items  per  cluster.  The  tree  graph  could  have  an unlimited number of levels, whereas the dendrogram always has $N-1$ clusters. The tree graph did not incorporate a notion of distance, whereas the dendrogram does.\"\n",
    "\n",
    "2. __In the second step, a correlation matrix is derived from the linkage object.__\n",
    "\n",
    " - One by one, the clusters (each represented by a link in the linkage object) are decomposed to lists of atoms contained in each of the two elements of the cluster.\n",
    "\n",
    " - The elements on the main diagonal of the resulting correlation matrix are set to 1s. The off-diagonal correlations between the variables are computed as:\n",
    "\n",
    "$$\\rho_{i,j} = 1 - 2 * d_{i,j}^{2}$$\n",
    "\n",
    "3. __In the third step, the correlation matrix is de-noised.__\n",
    "\n",
    "- The eigenvalues and eigenvectors of the correlation matrix are calculated.\n",
    "\n",
    "- Marcenko-Pastur distribution is fit to the eigenvalues of the correlation matrix and the maximum theoretical eigenvalue is calculated.\n",
    "\n",
    "- This maximum theoretical eigenvalue is set as a threshold and all the eigenvalues above the threshold are shrinked.\n",
    "\n",
    "- The de-noised correlation matrix is calculated back from the eigenvectors and the new eigenvalues.\n",
    "\n",
    "The algorithm for de-noising the correlation and the covariance matrix is implemented in the RiskEstimators class of the mlfinlab package. It is described in more detail [here](https://github.com/hudson-and-thames/research/blob/master/RiskEstimators/RiskEstimators.ipynb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "__Note:__\n",
    "\n",
    "\"If all variables depend directly from a single category, then the theory-implied correlation matrix will be the same as the empirical correlation matrix. That does not mean that the more structure is  imposed  by  the  economic  theory,  the  more  the  theory-implied  correlation  matrix  will  depart from the empirical correlation matrix. The degree of departure will depend on how much the tree graph forces the clustering of variables that the empirical correlation deems distant.\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Usage of the algorithm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's use the TIC algorithm on the set of ETFs. \n",
    "\n",
    "We will use the series of daily prices of the ETFs. We also need to determine the classification to use for the data. We will propose the classification of the ETFs similar to that of GICS. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import mlfinlab as ml\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import seaborn as sns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>EEM</th>\n",
       "      <th>EWG</th>\n",
       "      <th>TIP</th>\n",
       "      <th>EWJ</th>\n",
       "      <th>EFA</th>\n",
       "      <th>IEF</th>\n",
       "      <th>EWQ</th>\n",
       "      <th>EWU</th>\n",
       "      <th>XLB</th>\n",
       "      <th>XLE</th>\n",
       "      <th>...</th>\n",
       "      <th>XLU</th>\n",
       "      <th>EPP</th>\n",
       "      <th>FXI</th>\n",
       "      <th>VGK</th>\n",
       "      <th>VPL</th>\n",
       "      <th>SPY</th>\n",
       "      <th>TLT</th>\n",
       "      <th>BND</th>\n",
       "      <th>CSJ</th>\n",
       "      <th>DIA</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2008-01-03</th>\n",
       "      <td>0.008997</td>\n",
       "      <td>-0.002826</td>\n",
       "      <td>0.003376</td>\n",
       "      <td>0.003779</td>\n",
       "      <td>0.001662</td>\n",
       "      <td>0.002054</td>\n",
       "      <td>-0.000527</td>\n",
       "      <td>0.006281</td>\n",
       "      <td>0.018160</td>\n",
       "      <td>0.011824</td>\n",
       "      <td>...</td>\n",
       "      <td>-0.001426</td>\n",
       "      <td>0.002345</td>\n",
       "      <td>-0.006847</td>\n",
       "      <td>0.003623</td>\n",
       "      <td>0.002823</td>\n",
       "      <td>-0.000483</td>\n",
       "      <td>-0.001377</td>\n",
       "      <td>0.001293</td>\n",
       "      <td>0.001183</td>\n",
       "      <td>0.000842</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-01-04</th>\n",
       "      <td>-0.030037</td>\n",
       "      <td>-0.019552</td>\n",
       "      <td>-0.000280</td>\n",
       "      <td>-0.025602</td>\n",
       "      <td>-0.022719</td>\n",
       "      <td>0.002619</td>\n",
       "      <td>-0.024525</td>\n",
       "      <td>-0.023720</td>\n",
       "      <td>-0.030202</td>\n",
       "      <td>-0.036549</td>\n",
       "      <td>...</td>\n",
       "      <td>0.007614</td>\n",
       "      <td>-0.028139</td>\n",
       "      <td>-0.019125</td>\n",
       "      <td>-0.024332</td>\n",
       "      <td>-0.025630</td>\n",
       "      <td>-0.024506</td>\n",
       "      <td>0.000212</td>\n",
       "      <td>0.001162</td>\n",
       "      <td>0.001281</td>\n",
       "      <td>-0.019657</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-01-07</th>\n",
       "      <td>0.007327</td>\n",
       "      <td>0.000867</td>\n",
       "      <td>-0.000187</td>\n",
       "      <td>-0.006182</td>\n",
       "      <td>0.001045</td>\n",
       "      <td>0.001817</td>\n",
       "      <td>0.007299</td>\n",
       "      <td>0.002984</td>\n",
       "      <td>-0.013732</td>\n",
       "      <td>-0.003871</td>\n",
       "      <td>...</td>\n",
       "      <td>0.020779</td>\n",
       "      <td>0.011368</td>\n",
       "      <td>0.028971</td>\n",
       "      <td>-0.000411</td>\n",
       "      <td>-0.001824</td>\n",
       "      <td>-0.000849</td>\n",
       "      <td>0.004349</td>\n",
       "      <td>0.000258</td>\n",
       "      <td>0.000689</td>\n",
       "      <td>-0.000858</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-01-08</th>\n",
       "      <td>-0.007754</td>\n",
       "      <td>-0.006930</td>\n",
       "      <td>0.000748</td>\n",
       "      <td>-0.002333</td>\n",
       "      <td>-0.005610</td>\n",
       "      <td>0.002154</td>\n",
       "      <td>-0.007783</td>\n",
       "      <td>-0.014025</td>\n",
       "      <td>-0.015415</td>\n",
       "      <td>-0.017487</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000231</td>\n",
       "      <td>-0.016860</td>\n",
       "      <td>-0.014078</td>\n",
       "      <td>-0.007539</td>\n",
       "      <td>-0.004417</td>\n",
       "      <td>-0.016148</td>\n",
       "      <td>-0.001162</td>\n",
       "      <td>0.001031</td>\n",
       "      <td>0.000197</td>\n",
       "      <td>-0.017258</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2008-01-09</th>\n",
       "      <td>0.032780</td>\n",
       "      <td>0.003199</td>\n",
       "      <td>-0.000747</td>\n",
       "      <td>0.021824</td>\n",
       "      <td>0.007216</td>\n",
       "      <td>-0.001584</td>\n",
       "      <td>0.002975</td>\n",
       "      <td>0.000431</td>\n",
       "      <td>0.006313</td>\n",
       "      <td>0.013184</td>\n",
       "      <td>...</td>\n",
       "      <td>0.010870</td>\n",
       "      <td>0.019435</td>\n",
       "      <td>0.062779</td>\n",
       "      <td>0.001381</td>\n",
       "      <td>0.021267</td>\n",
       "      <td>0.010510</td>\n",
       "      <td>0.001903</td>\n",
       "      <td>-0.001159</td>\n",
       "      <td>-0.000885</td>\n",
       "      <td>0.008820</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 23 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                 EEM       EWG       TIP       EWJ       EFA       IEF  \\\n",
       "Date                                                                     \n",
       "2008-01-03  0.008997 -0.002826  0.003376  0.003779  0.001662  0.002054   \n",
       "2008-01-04 -0.030037 -0.019552 -0.000280 -0.025602 -0.022719  0.002619   \n",
       "2008-01-07  0.007327  0.000867 -0.000187 -0.006182  0.001045  0.001817   \n",
       "2008-01-08 -0.007754 -0.006930  0.000748 -0.002333 -0.005610  0.002154   \n",
       "2008-01-09  0.032780  0.003199 -0.000747  0.021824  0.007216 -0.001584   \n",
       "\n",
       "                 EWQ       EWU       XLB       XLE  ...       XLU       EPP  \\\n",
       "Date                                                ...                       \n",
       "2008-01-03 -0.000527  0.006281  0.018160  0.011824  ... -0.001426  0.002345   \n",
       "2008-01-04 -0.024525 -0.023720 -0.030202 -0.036549  ...  0.007614 -0.028139   \n",
       "2008-01-07  0.007299  0.002984 -0.013732 -0.003871  ...  0.020779  0.011368   \n",
       "2008-01-08 -0.007783 -0.014025 -0.015415 -0.017487  ...  0.000231 -0.016860   \n",
       "2008-01-09  0.002975  0.000431  0.006313  0.013184  ...  0.010870  0.019435   \n",
       "\n",
       "                 FXI       VGK       VPL       SPY       TLT       BND  \\\n",
       "Date                                                                     \n",
       "2008-01-03 -0.006847  0.003623  0.002823 -0.000483 -0.001377  0.001293   \n",
       "2008-01-04 -0.019125 -0.024332 -0.025630 -0.024506  0.000212  0.001162   \n",
       "2008-01-07  0.028971 -0.000411 -0.001824 -0.000849  0.004349  0.000258   \n",
       "2008-01-08 -0.014078 -0.007539 -0.004417 -0.016148 -0.001162  0.001031   \n",
       "2008-01-09  0.062779  0.001381  0.021267  0.010510  0.001903 -0.001159   \n",
       "\n",
       "                 CSJ       DIA  \n",
       "Date                            \n",
       "2008-01-03  0.001183  0.000842  \n",
       "2008-01-04  0.001281 -0.019657  \n",
       "2008-01-07  0.000689 -0.000858  \n",
       "2008-01-08  0.000197 -0.017258  \n",
       "2008-01-09 -0.000885  0.008820  \n",
       "\n",
       "[5 rows x 23 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Getting the price data for ETFs\n",
    "etf_prices = pd.read_csv('../Sample-Data/stock_prices.csv', parse_dates=True, index_col='Date')\n",
    "\n",
    "# We need to calculate the series of returns from a series of prices to calculate the correlation matrix\n",
    "\n",
    "# Class with returns calculation function\n",
    "ret_est = ml.portfolio_optimization.ReturnsEstimation()\n",
    "\n",
    "# Calculating returns\n",
    "etf_returns = ret_est.calculate_returns(etf_prices)\n",
    "\n",
    "# Having a look at the result that we've obtained\n",
    "etf_returns.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TICKER</th>\n",
       "      <th>SECTOR</th>\n",
       "      <th>REGION</th>\n",
       "      <th>TYPE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>EEM</td>\n",
       "      <td>101010</td>\n",
       "      <td>1010</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>EWG</td>\n",
       "      <td>102010</td>\n",
       "      <td>1020</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>TIP</td>\n",
       "      <td>203010</td>\n",
       "      <td>2030</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>EWJ</td>\n",
       "      <td>104010</td>\n",
       "      <td>1040</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>EFA</td>\n",
       "      <td>103010</td>\n",
       "      <td>1030</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>IEF</td>\n",
       "      <td>203010</td>\n",
       "      <td>2030</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>EWQ</td>\n",
       "      <td>102010</td>\n",
       "      <td>1020</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>EWU</td>\n",
       "      <td>102010</td>\n",
       "      <td>1020</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>XLB</td>\n",
       "      <td>103020</td>\n",
       "      <td>1030</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>XLE</td>\n",
       "      <td>103030</td>\n",
       "      <td>1030</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>XLF</td>\n",
       "      <td>103040</td>\n",
       "      <td>1030</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>LQD</td>\n",
       "      <td>203020</td>\n",
       "      <td>2030</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>XLK</td>\n",
       "      <td>103050</td>\n",
       "      <td>1030</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>XLU</td>\n",
       "      <td>103060</td>\n",
       "      <td>1030</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>EPP</td>\n",
       "      <td>104010</td>\n",
       "      <td>1040</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>FXI</td>\n",
       "      <td>104010</td>\n",
       "      <td>1040</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>VGK</td>\n",
       "      <td>102010</td>\n",
       "      <td>1020</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>VPL</td>\n",
       "      <td>104010</td>\n",
       "      <td>1040</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>SPY</td>\n",
       "      <td>103010</td>\n",
       "      <td>1030</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>TLT</td>\n",
       "      <td>203010</td>\n",
       "      <td>2030</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>BND</td>\n",
       "      <td>203010</td>\n",
       "      <td>2030</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>CSJ</td>\n",
       "      <td>203010</td>\n",
       "      <td>2030</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>DIA</td>\n",
       "      <td>103010</td>\n",
       "      <td>1030</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   TICKER   SECTOR   REGION   TYPE\n",
       "0     EEM   101010     1010     10\n",
       "1     EWG   102010     1020     10\n",
       "2     TIP   203010     2030     20\n",
       "3     EWJ   104010     1040     10\n",
       "4     EFA   103010     1030     10\n",
       "5     IEF   203010     2030     20\n",
       "6     EWQ   102010     1020     10\n",
       "7     EWU   102010     1020     10\n",
       "8     XLB   103020     1030     10\n",
       "9     XLE   103030     1030     10\n",
       "10    XLF   103040     1030     10\n",
       "11    LQD   203020     2030     20\n",
       "12    XLK   103050     1030     10\n",
       "13    XLU   103060     1030     10\n",
       "14    EPP   104010     1040     10\n",
       "15    FXI   104010     1040     10\n",
       "16    VGK   102010     1020     10\n",
       "17    VPL   104010     1040     10\n",
       "18    SPY   103010     1030     10\n",
       "19    TLT   203010     2030     20\n",
       "20    BND   203010     2030     20\n",
       "21    CSJ   203010     2030     20\n",
       "22    DIA   103010     1030     10"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Now the empirical correlation matrix can be calculated\n",
    "etf_corr = etf_returns.corr()\n",
    "\n",
    "# Getting the tree graph for ETFs\n",
    "etf_tree = pd.read_csv('../Sample-Data/classification_tree.csv')\n",
    "\n",
    "# Having a look at the tree structure of ETFs\n",
    "etf_tree"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "A proposed tree structure for ETFs has four levels:\n",
    "\n",
    "1. Type of the ETF\n",
    " - 10 - Equity ETF\n",
    " - 20 - Bond ETF\n",
    "2. Region of the ETF\n",
    " - XX10 - Emerging markets\n",
    " - XX20 - Europe\n",
    " - XX30 - US and Canada\n",
    " - XX40 - Asia\n",
    "3. Sector of the ETF\n",
    " - XXXX10 - General/No sector\n",
    " - XXXX20 - Materials\n",
    " - XXXX30 - Energy\n",
    " - XXXX40 - Financial\n",
    " - XXXX50 - Technology\n",
    " - XXXX60 - Utilities\n",
    "4. Ticker of the ETF\n",
    "\n",
    "Now we can use the algorithm to calculate the theory-implied correlation matrix."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Calculating the relation of sample length T to the number of variables N\n",
    "# It's used for de-noising the TIC matrix\n",
    "tn_relation = etf_returns.shape[0] / etf_returns.shape[1]\n",
    "\n",
    "# Class with TIC function\n",
    "tic = ml.portfolio_optimization.TIC()\n",
    "\n",
    "# Calculating theory-implied correlation matrix\n",
    "etf_tic = tic.tic_correlation(etf_tree, etf_corr, tn_relation, kde_bwidth=0.01)\n",
    "\n",
    "# Setting the indexes of the theory-implied correlation matrix\n",
    "etf_tic = pd.DataFrame(etf_tic, index=etf_corr.index, columns=etf_corr.index)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can visualize the difference between the Empirical correlation matrix and the Theory-implied correlation matrix using heatmaps."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x133fbe2ee48>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXMAAAEKCAYAAADgl7WbAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO2deZwdVdG/n+9MkslkJWEXkDXsYlhUxA0UBX2V4Csoq6BgfiqI6CuKrxuKCwquGNHoiwFFoyBC1IgKgoiCEiASEgMJiyQk7CEbWSf1+6N7Qqen752ue+/M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ppmZKR/w5I5zuXX1IgX9pw9XM8x+kaKqCZkLQ885svy/3+L+pr/RrE/5J8AN3HzN5mZldZiRSETUR2bPT8cLhFDa6gh2jqoCErGFa2G/qt4XLiOU7v203TYGYj+1qHnsZKjvzYxLxU0jLS8VvSedLlakFCQYNpamNeA/3WcDnxHGfcbEGPUUODK+ghmnoIXC+SOkhGZOsc5a0z04lIgjAa4a/uczaX4wyCoDwDypgHQRBsrjT7B9AgCIKgBGHMgyAIBgBhzIMgCAYAYcyDIAgGAP8f0CJTdfRPDiQAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Plotting the heatmap of the Empirical correlation matrix\n",
    "sns.heatmap(etf_corr, cmap=\"Greens\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot at 0x133fdfe27c8>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAWsAAAEKCAYAAADU7nSHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO2deZwdVbW2n7cTuDImICAIkXkQEZkUxInBISiTV1AGB65orvcTEbwOgAIBFFFUFEE0eiHCRcEREAN4URARxESITIIySQIoCEhAQUhY3x9VHSrVdU7XPn1Od53O+/Svfl21a9Xeq+pUrdq19rAUERhjjGk2A2OtgDHGmOGxsTbGmD7AxtoYY/oAG2tjjOkDbKyNMaYPsLE2xpg+IMlYS1okaW5hOSJPv1LS7YX0H+Tp0yWFpI0KeRyep23X3V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2KUb8vkxu5N1O3uYbFa8q8iG8beS79WLo+X8LeXtxN/vw7mxugf4HLBVzeOWIWvEOzc3lucDe1fI3Uz+9UD2pfra4r6RngdZDb/l0uKYnXnuK6Ldb9/ui6Srz1E/LGOuwDA3QlINtbCvtmFK0KX2w9qrB7uT8yRrhHsgf1DPAt4HbN4iv1TjOzh6rehK2Iqs9vTdkcoPc+6HjVD3VPmevoCp79Z4A1nvmL8CPyFr0FuhTb6fJGtfuTDPe3BsxUbAr0uyyV+cLcpcbbCcEeYz+HVS9cX5TDd07adlzBUY5sdK/fSsbZh6qcsoPNgpBri2r70D49uuJlrlm0ySH0bXe0vbPX1x0N6t0VXDQXu3xhVkXUZrG1ayBui3Fo062RfZNl3QdQcyt8aPcr1vJqvpPwhM7eZ1WdqXMVdgmBshqYaaYpg60KX2w9rrBzvRAKf42rtmTEfh3pg3Et2bdq7UdGs0bSFrN3kj2VQKj5LNwgdZIIKlrhGwl0vTw3pFi/WqbYDNIuJvAJL2Le6QdOKIFImYEBErR8RKETExXx/cXqZT2Q5JOc/9CutHlvZNLek9JNJMYd83W+0bI5b4/VN1b8q5SnqDpDPJfObTyIIObBgR74iIC0ZLjxEwMSJ+FhHfB/4S+dSuEXHbGOs17mi6sX6ZpAXKZo7bMl8f3H5phXxtw9TnpJxn0lD2JiHp8cJvvqD0+79wrPXrEkeRNTC+OCL2iIhzo0aIuAZRnBu7PF1qVYXKdEijB8VExbSjw9C3himRlPNM/TppDBGx0ljr0Gui5syBDeZlkhaQzx+Sr5NvtxsEYxJptLHugL41TImknKcfJtMzOqhQmQ5p9BSpqUhaRDaj1+AsYYORKkQ2yKAb/uIxZ2k5T2PMc4wrY22MMeOVpjcwGmOMwcbaGGP6AhtrY4zpA2ysjTGmD/j/f/BgQ9i7lioAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Plotting the heatmap of the Theory-implied correlation matrix\n",
    "sns.heatmap(etf_tic, cmap=\"Greens\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can see that the Theory-implied correlation matrix is less noisy and has a clearly defined structure in comparison to the Empirical correlation matrix."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "If we want to measure the similarity of the Empirical correlation matrix and the Theory-implied correlation matrix, we can use the correlation matrix distance introduced by _Herdin_ and _Bonek_ in a paper __AMIMO Correlation Matrix based Metric for Characterizing Non-Stationarity__ [available here](https://publik.tuwien.ac.at/files/pub-et_8791.pdf). The distance is calculated as:\n",
    "\n",
    "$$d[\\sum_{1},\\sum_{2}] = 1 - \\frac{tr(\\sum_{1}\\sum_{2})}{||\\sum_{1}||_f||\\sum_{2}||_f}$$\n",
    "\n",
    "Where $\\sum_{1},\\sum_{2}$ are the two correlation matrices and the $||.||_f$ is the Frobenius norm.\n",
    "\n",
    "\"The distance $d[\\sum_{1},\\sum_{2}]$ measures the orthogonality between the considered correlation matrices. It becomes zero if the correlation matrices are equal up to a scaling factor, and one if they differ to a maximum extent\"."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The distance between empirical and the theory-implied correlation matrices is 0.035661302090136515\n"
     ]
    }
   ],
   "source": [
    "# Calculating the correlation matrix distance\n",
    "distance = tic.corr_dist(etf_corr, etf_tic)\n",
    "\n",
    "# Printing the result\n",
    "print('The distance between empirical and the theory-implied correlation matrices is' , distance)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The correlation matrices are different but are not too far apart. This shows that the theory-implied correlation matrix blended theory-implied views with empirical ones."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Conclusion"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebook describes the Theory-Implied Correlation (TIC) algorithm and the correlation matrix distance metric. Also, it shows how these can be used on some real examples.\n",
    "\n",
    "The algorithms and the descriptions were originally presented by _Marcos Lopez de Prado_ in the paper __Estimation of Theory-Implied Correlation Matrices__  [available here](https://papers.ssrn.com/sol3/abstract_id=3484152).\n",
    "\n",
    "Key takeaways from the notebook:\n",
    "- Empirical correlation matrices have poor numerical properties and predictive power.\n",
    "- Correlation matrices lack the user-defined structure based on economic theory or alternative approaches.\n",
    "- The TIC algorithm estimates the forward-looking correlation matrix implied by a proposed hierarchical structure of the assets. \n",
    "- The algorithm combines empirical data - the correlation matrix of the assets with the fundamental structure provided by the economic theory - the hierarchical structure of the assets.\n",
    "- The tree graph used in the TIC algorithm can have as many levels as needed, with one or more leaves per branch, and some branches may include more levels than other branches.\n",
    "- This empirical correlation matrix used in the TIC algorithm must be symmetric, and include a main diagonal of 1s. However, the empirical correlation matrix does not need to be invertible, positive definite or non-singular.\n",
    "- The TIC algorithm consists of three steps:\n",
    "  - In the first step, the theoretical tree graph structure of the assets is fit on the evidence presented by the empirical correlation matrix.\n",
    "  - In the second step, a correlation matrix is derived from the linkage object.\n",
    "  - In the third step, the correlation matrix is de-noised.\n",
    "- The MSCI’s Global Industry Classification Standard (GICS) can be used to classify investment universes in terms of four nested levels.\n",
    "- The similarity of the Empirical correlation matrix and the Theory-implied correlation matrix can be measured using the correlation matrix distance introduced by Herdin and Bonek."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "mlfinlab",
   "language": "python",
   "name": "mlfinlab"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
